package cn.group.controller;

import cn.group.service.LineChartService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.qo.UserLog;
import utils.BaseController;

import java.util.List;

@Api(tags = "折线图")
@Controller
@RequestMapping(value = "/lineChart" , produces = "text/html;charset=UTF-8")
public class LineChartController extends BaseController {

    @Autowired
    private LineChartService lineChartService;

    @ApiOperation("删除全部数据")
    @RequestMapping(value = "/deleteLog.do")
    @ResponseBody
    public String deleteAll(@RequestParam(value = "log[]") Long[] log){
        System.out.println(log);
        for (int i = 0; i < log.length; i++) {
            lineChartService.deleteLog(log[i]);
        }
        return writerSuccessResult("删除成功！");
    }

    @ApiOperation("查询所有用户登录信息")
    @RequestMapping(value = "/getLogMassage.do")
    @ResponseBody
    public String getLogMassage(int newPages){
        List<UserLog> logMassage = lineChartService.getLogMassage(newPages);
        PageInfo pageInfo=new PageInfo(logMassage);
        int pages = pageInfo.getPages();
        if (newPages<1){
            return writerErrorResult("已经是第一页");
        }else if (newPages>pages){
            return writerErrorResult("已经是最后一页了");
        }else {
            String logs = writerSuccessResult(logMassage);
            return logs;
        }
    }

    @ApiOperation("获取时间")
    @RequestMapping(value = "/userDate.do")
    @ResponseBody
    public String userDate(){

        System.out.println("获取时间");

        int [] ints = lineChartService.userDate();
        String s = writerSuccessResult(ints);
        System.out.println("userDate"+s);
        return s;
    }

    @ApiOperation("获取登录量")
    @RequestMapping(value = "/userLogin.do")
    @ResponseBody
    public String userLogin(){
        int[] ints = lineChartService.userLogin();
        String s = writerSuccessResult(ints);
        System.out.println("userLogin"+s);
        return s;
    }

    @ApiOperation("获取注册量")
    @RequestMapping(value = "/userRegister.do")
    @ResponseBody
    public String userRegister(){
        int[] ints = lineChartService.userRegister();
        String s = writerSuccessResult(ints);
        System.out.println("userRegister"+s);
        return s;
    }

    @ApiOperation("获取订单数量")
    @RequestMapping(value = "/userOrder.do")
    @ResponseBody
    public String userOrder(){
        int[] ints = lineChartService.userOrder();
        String s = writerSuccessResult(ints);
        System.out.println("userOrder"+s);
        return s;
    }

    @ApiOperation("获取商品数量")
    @RequestMapping(value = "/userGood.do")
    @ResponseBody
    public String userGood(){
        int[] ints = lineChartService.userGood();
        String s = writerSuccessResult(ints);
        System.out.println("userGood"+s);
        return s;
    }
}
